﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

/**
 * A very simple level for facilitating the loading of different levels.
 */
public class EditorLoader : EnvBase
{
    // Member vars here
    private Levels.List m_currChoice;

    public EditorLoader()
    {
        m_currChoice = 0;
    }

    public override void update(double dt)
    {
        InputManager im = InputManager.getSingleton();
        im.update();

        if(im.getJustPressedControlState(InputManager.DOWN_BUTTON)) { m_currChoice++; }
        else if(im.getJustPressedControlState(InputManager.UP_BUTTON)) { m_currChoice--; }

        // Cap choices to proper limit
        if (m_currChoice < 0) { m_currChoice = 0; }
        else if (m_currChoice >= Levels.List.kCount) { m_currChoice = Levels.List.kCount-1; }

        Console c = Game.getGame().getConsole();
        c.print("Load which level?");
        for (Levels.List i = 0; i < Levels.List.kConsole-1; ++i)
        {
            if (i < Levels.List.kCount)
            {
                // Print our level. Mark it if it's our current selection
                c.print((i == m_currChoice ? ">>" : "") + Levels.s_names[(int)i] + (i == m_currChoice ? "<<" : ""));
            }
            else
            {
                c.print("");
            }
        }

        if(im.getJustPressedControlState(InputManager.PAUSE_BUTTON))
        {
            m_parentStack.popOnce(new EditorEnv(m_currChoice));
        }
        else if(im.getJustPressedControlState(InputManager.BACK_BUTTON))
        {
            m_parentStack.popOnce();
        }
    }

    public override void render()
    {
    }
}
